public class HomeWork14_09{
    public static void main(String[] args){
        int[][] magicArr = new int[][]{
            {17, 24, 1, 8, 15},
            {23, 5, 7, 14, 16},
            {4, 6, 13, 20, 22},
            {10, 12, 19, 21, 3},
            {11, 18, 25, 2, 9}
        };
        
        System.out.println("是否为魔方矩阵: " + MagicRec.isMagicRec(magicArr));
    }
}

class MagicRec{
    static public boolean isMagicRec(int[][] arr){
        boolean flag = false;
        int val = 0;
        for(int i = 0; i < arr.length; i++){
            int rowVal = 0;
            int colVal = 0;
            for(int j = 0; j < arr[i].length; j++){
                rowVal += arr[i][j];
                colVal += arr[j][i];
            }
            if(rowVal != colVal){
                return false;
            }
            if(!flag){
                flag = true;
                val = rowVal;
            }else if(rowVal != val){
                return false;
            }
        }
        return true;
    }
}